#include "Tools/RIVIAPencilTool.h"
#include "IRIVIAPalette.h"
#include "opencv2/core.hpp"
#include <QVector>

using namespace cv;

RIVIAPencilTool::RIVIAPencilTool()
{

}

RIVIAPencilTool::~RIVIAPencilTool()
{

}

void RIVIAPencilTool::applyOnScreen(int x, int y)
{
    updateROI(x, y);

    QVector<int> color = IRIVIAPalette().getCurColor();

    MatIterator_<uchar> brushit = m_brushroi_mat.begin<uchar>();
    MatIterator_<Vec3b> roiit = m_roi_mat.begin<Vec3b>();
    MatIterator_<Vec3b> roiprocit = m_roi_matproc.begin<Vec3b>();

    for(; brushit != m_brushroi_mat.end<uchar>(); ++brushit)
    {
        if((*brushit) != 0)
        {
            (*roiit)[0] = color[2];
            (*roiit)[1] = color[1];
            (*roiit)[2] = color[0];
            (*roiprocit)[0] = color[2];
            (*roiprocit)[1] = color[1];
            (*roiprocit)[2] = color[0];
        }
        ++roiit;
        ++roiprocit;
    }
}
